This repository was archived by the owner on Jun 3, 2026. It is now read-only.
feat(wasm): add hook-provider interface for bidirectional host control#998
Open
mathpal wants to merge 1 commit into
Open
feat(wasm): add hook-provider interface for bidirectional host control#998mathpal wants to merge 1 commit into
mathpal wants to merge 1 commit into
Conversation
Add a WIT hook-provider contract and HookProviderBridge plugin that forwards SDK lifecycle hooks (before/after invocation, model call, tool call, tools batch) across the WASM boundary to host-side handlers. The bridge uses capability negotiation so hosts only receive hooks they declare support for. Key behaviors: - Cancel decisions propagated from host to guest - Tool-use rewrite (partial field updates preserve originals) - Tool selection override via selectedToolName - Result replacement via after-tool-call - Model/tool retry signaling - Resume from after-invocation with arbitrary InvokeArgs JSON Includes Python host stubs, comprehensive unit tests covering partial rewrites, multi-tool batch cancel, retry chains, and malformed JSON graceful degradation.
Collaborator
|
This repository has been merged into the strands-agents/harness-sdk monorepo and will be archived shortly. All new development happens there. If this PR is still relevant, please recreate it against the monorepo. The code now lives under Apologies for the disruption, and thank you for contributing! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
WASM hosts (Rust SDK, future language bindings) need to control the agent lifecycle — cancel expensive operations, enforce policies, redact secrets, retry on transient failures — without forking or modifying the guest. The existing
LifecycleBridgeis observation-only (unidirectional). This adds a bidirectionalhook-providerWIT contract so hosts can make decisions at each lifecycle point.Public API Changes
New WIT import
hook-providerwith 9 functions (8 lifecycle hooks + capability negotiation). The guest calls out to the host at each lifecycle point and receives a decision:Hosts declare supported hooks via
get-capabilities(). Unsupported hooks are never called (zero overhead for hosts that don't use them).Modification capabilities
Scope: Control-Plane Hooks (not full TS SDK parity)
This patch gives WASM hosts control-plane capabilities — the ability to cancel, retry, redirect, and mutate operations. It does NOT expose the full set of TS SDK hook event types or read access to agent state.
What WASM hosts get (7 of 15 TS SDK hookable events):
BeforeInvocationEvent,AfterInvocationEventBeforeModelCallEvent,AfterModelCallEventBeforeToolsEvent,AfterToolsEventBeforeToolCallEvent,AfterToolCallEventWhat WASM hosts do NOT get:
event.agent,event.messages,event.model, orevent.toolreferencesInitializedEvent,MessageAddedEvent,AgentResultEventModelStreamUpdateEvent,ContentBlockEvent, etc.)AfterModelCallEventonly receivesstopReason+ error, not the fullModelStopDatamessageThese are deliberate limitations of the WIT boundary — full state access would require serializing the entire agent on every hook call. The existing
LifecycleBridgestream events remain available for observation.Python host state
Python (
_wasm_host.py) registers no-op stubs that return zero-value decisions and an empty capabilities list. This means no hooks fire in Python today — the stubs exist solely to satisfy the WIT linker. A follow-up PR will add a Python-side hook registration API (WasmAgent(hooks=...)) that wires user callbacks to the WIT functions.Breaking Changes
Adding
import hook-providerto the WIT world makes it a required import. Every host must implement all 9 functions. The Python host already has stubs. Any new host language binding must provide stubs (all returning zero-value decisions) to link successfully.